import request from "@/utils/request"
import server from '@/utils/server'

export interface shopCartData{
  "id": number,
  "userId": string,
  "skuId": any,
  "cartPrice": number,
  "skuNum": number,
  "imgUrl": string,
  "skuName": string,
  "isChecked": number,
  "createTime":string,
  "operateTime": string,
  "isOrdered": number,
  "orderTime": null,
  "sourceType": string,
  "sourceId": number,
  "skuPrice": number,
  "couponInfoList": null
  // cartInfoList:any
}

export interface tokenData{
  "code": number,
  "message": string,
  data:tokenUserData
}
export interface tokenUserData{
"token": string
}

export interface addShopData{
  "code": number,
  "message": string,
  "data": null,
  "ok": true
}

export interface dataData{
  phone:string,
  password:string
}
export default{
  // 商品信息的接口
  getShopList(){
    return server.get('/api/cart/cartList')
  },

  // 用户信息的接口
  getToken(data:dataData){
    return server.post<any,tokenData>('/api/user/passport/login',data)
  },

  // 加入购物车
  addShopCart(skuId:number,skuNum:number){
    return server.post<addShopData,null>(`/api/cart/addToCart/${skuId}/${skuNum}`)
  },

  // 删除单个商品
  deleteOne(skuId:string){  
    return server.delete<any,null>(`/api/cart/deleteCart/${skuId}`)
  },

  // 切换商品选中状态
  checkOne(skuId:number,isChecked:number){
    return server.get(`/api/cart/checkCart/${skuId}/${isChecked}`)
  }
}